<template>
<div>
    <el-form :model="inputForm" ref="inputForm" v-loading="loading"   :disabled="formReadOnly"
             label-width="120px">
      <el-row  :gutter="15">
        <el-col :span="24">
            <el-form-item label="部门" prop="parts"
                :rules="[
                 ]">
              <el-input v-model="inputForm.parts" placeholder="请填写部门"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="物料代码" prop="materialCode"
                :rules="[
                 ]">
              <el-input v-model="inputForm.materialCode" placeholder="请填写物料代码"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="物料名称" prop="materialName"
                :rules="[
                 ]">
              <el-input v-model="inputForm.materialName" placeholder="请填写物料名称"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="规格型号" prop="specifications"
                :rules="[
                 ]">
              <el-input v-model="inputForm.specifications" placeholder="请填写规格型号"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="计量单位" prop="measuringUnit"
                :rules="[
                 ]">
              <el-input v-model="inputForm.measuringUnit" placeholder="请填写计量单位"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="ABC分类" prop="classification"
                :rules="[
                 ]">
              <el-input v-model="inputForm.classification" placeholder="请填写ABC分类"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="数量" prop="number"
                :rules="[
                 ]">
              <el-input v-model="inputForm.number" placeholder="请填写数量"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="ERP领料人" prop="erpPickingPeople"
                :rules="[
                 ]">
              <el-input v-model="inputForm.erpPickingPeople" placeholder="请填写ERP领料人"     ></el-input>
           </el-form-item>
        </el-col>
        </el-row>
    </el-form>
</div>
</template>

<script>
  export default {
    props: {
      businessId: {
        type: String,
        default: ''
      },
      formReadOnly: {
        type: Boolean,
        default: false
      },
      outPutForm: {
        parts: '',
        specifications: '',
        materialCode: '',
        materialName: '',
        classification: '',
        number: '',
        erpPickingPeople: '',
        measuringUnit: ''
      }
    },
    data () {
      return {
        title: '',
        method: '',
        loading: false,
        inputForm: {
          id: '',
          parts: this.outPutForm.parts,
          materialCode: this.outPutForm.materialCode,
          materialName: this.outPutForm.materialName,
          specifications: this.outPutForm.specifications,
          measuringUnit: this.outPutForm.measuringUnit,
          classification: this.outPutForm.classification,
          number: this.outPutForm.number,
          erpPickingPeople: this.outPutForm.erpPickingPeople
        }
      }
    },
    components: {
    },
    watch: {
      'inputForm.parts': function (newVal, oldVal) {
        console.log(newVal)
        console.log(oldVal)
        console.log(this.inputForm.parts)
      },
      'businessId': {
        handler (newVal) {
          if (this.businessId) {
            this.init(this.businessId)
          } else {
            this.$nextTick(() => {
              this.$refs.inputForm.resetFields()
            })
          }
        },
        immediate: true,
        deep: false
      }
    },
    methods: {
      init (id) {
        if (id) {
          this.loading = true
          this.inputForm.id = id
          this.$nextTick(() => {
            this.$refs.inputForm.resetFields()
            this.$http({
              url: `/spareparts/material/sparepartPutLibraryForm/queryById?id=${this.inputForm.id}`,
              method: 'get'
            }).then(({data}) => {
              this.inputForm = this.recover(this.inputForm, data.sparepartPutLibraryForm)
              this.loading = false
            })
          })
        }
      },
      // 表单提交
      saveForm (callback) {
        this.$refs['inputForm'].validate((valid) => {
          if (valid) {
            this.loading = true
            this.$http({
              url: `/spareparts/material/sparepartPutLibraryForm/save`,
              method: 'post',
              data: this.inputForm
            }).then(({data}) => {
              if (data && data.success) {
                callback(data.businessTable, data.businessId)
              }
            })
          }
        })
      }
    }
  }
</script>
